<script setup lang="ts">
import { useRouter } from 'vue-router'
const props = defineProps<{
  title?: string
  rightText?: string
  goBackFn?: () => void
}>()

const emit = defineEmits<{
  (name: 'click-right'): void
}>()

const clickRight = () => {
  // 右侧点击
  console.log('右侧点击')
  emit('click-right')
}

const router = useRouter()
const clickLeft = () => {
  // this.$router.back()
  if (props.goBackFn) {
    // 外面如果传入自定义后退函数, 就执行
    props.goBackFn()
  } else {
    router.back()
  }
}
</script>

<template>
  <van-nav-bar
    left-arrow
    fixed
    placeholder
    :title="title"
    :right-text="rightText"
    @click-right="clickRight"
    @click-left="clickLeft"
  />
</template>

<style lang="scss" scoped>
::v-deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }

    &__text {
      font-size: 15px;
    }
  }
}
</style>
